debugger;
console.log("in rahul js file");

// write your code here
// script file added by ankur for using in the xml gadget

//alert("from the script file -  this is a seperate js");




function callWebService(remoteMethodName, inputData, successHandler, extraInfo) {
    debugger;
    var serverString = "http://demo.ivp.in:9056/TaskManagement.svc/";
    $.ajax({
        type: "GET",
        url: serverString + remoteMethodName,
        processData: false,
        contentType: "application/json; charset=utf-8",
        data: inputData,
        dataType: "json",
        success: successHandler,
        error: null,
        userContext: extraInfo
    });
    //////debugger;;

}

function successHandler(result) {

    debugger;
    console.log(result.d);
    console.log("callback web service");
}


var success_Handler1 = function (output) {
    debugger;
    console.log(JSON.parse(gadgets.json.parse(output.data).d));
    //console.log(output.data);
    //console.log("callback");
    //alert(output);
};




function replaceAll(find, replace, str) {
    return str.replace(new RegExp(find, 'g'), replace);
}

var testAjaxCall = function () {
    //console.log("testing aJAX");
    //callWebService("GetWorkspaceAccordianJSON", JSON.stringify({'user_id': 20 }), function (output) { successHandler(output); }, "");
    //var inputData = JSON.stringify({'userId': '20' });

    //inputData = gadgets.io.encodeValues(inputData)
    // callWebService("GetUpdateTaskCount", "", function (output) { successHandler(output); }, "");

    var inputData = { "user_id": "708" };
    var inputData1 = JSON.stringify({ "user_id": 708 });
    var inputData2 = "{ user_id: 708 }";
    var inputData3 = JSON.stringify({ "user_id": 708 });

    var params = {};
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params[gadgets.io.RequestParameters.POST_DATA] = inputData;
    params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;

    var params1 = {};
    params1[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params1[gadgets.io.RequestParameters.POST_DATA] = inputData1;
    //params1[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
    params1.HEADERS={};
    params1.HEADERS["Content-Type"] = "application/json";
    //params1.HEADERS[gadgets.io.RequestParameters.CONTENT_TYPE]= "application/json";        

    var params2 = {};
    params2[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params2[gadgets.io.RequestParameters.POST_DATA] = inputData2;
    params2[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;
    // params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;

    var params3 = {};
    params3[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params3[gadgets.io.RequestParameters.POST_DATA] = inputData2;
    params3[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.JSON;


    //params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(inputData);


    // var url =  "http://demo.ivp.in:9056/TaskManagement.svc/GetDefaultDashboard";   
    //var url =  "https://karma.ivp.in/TaskManagement.svc/GetUpdateTaskCount";   
    //var url = "https://karma.ivp.in/TaskManagement.svc/GetWorkspaceAccordianJSON";
    
    var url = "https://karma.ivp.in/TaskManagement.svc/GetWorkspaceAccordianJSON";
    debugger;
    
    
    //gadgets.io.makeRequest(url, success_Handler1, params);
   gadgets.io.makeRequest(url, success_Handler1, params1);
    //gadgets.io.makeRequest(url, success_Handler1, params2);
    //gadgets.io.makeRequest(url, success_Handler1, params3);


    //inputData = replaceAll("'", '"', inputData);
    //callWebService("GetMyWorkspaces", inputData, successHandler , null);
} ();

//params.HEADERS={}
//params.HEADERS["Content-Type"]= "application/json"


console.log("rahul code ends");

